/**
 * 节点日志管理相关 API
 */

import { get } from '@/utils/request'

/**
 * 节点日志
 */
export interface NodeLog {
  logId: number
  nodeId: string
  logLevel: 'Debug' | 'Info' | 'Warning' | 'Error'
  operationType: string
  message: string
  details: string | null
  timestamp: string
}

/**
 * 日志统计
 */
export interface LogStatistics {
  totalLogs: number
  errorCount: number
  warningCount: number
  infoCount: number
  debugCount: number
  byOperationType: Record<string, number>
}

/**
 * 日志查询参数
 */
export interface LogQueryParams {
  limit?: number
  offset?: number
  logLevel?: string
  operationType?: string
  startDate?: string
  endDate?: string
  nodeId?: string
}

/**
 * 获取节点日志
 */
export function getNodeLogs(nodeId: string, params?: LogQueryParams): Promise<NodeLog[]> {
  return get<NodeLog[]>(`/api/NodeLog/node/${nodeId}`, { params })
}

/**
 * 获取任务日志
 */
export function getTaskNodeLogs(taskId: number, params?: LogQueryParams): Promise<NodeLog[]> {
  return get<NodeLog[]>(`/api/NodeLog/task/${taskId}`, { params })
}

/**
 * 获取流水线实例日志
 */
export function getPipelineNodeLogs(
  pipelineInstanceId: number,
  params?: LogQueryParams
): Promise<NodeLog[]> {
  return get<NodeLog[]>(`/api/NodeLog/pipeline/${pipelineInstanceId}`, { params })
}

/**
 * 获取最近日志
 */
export function getRecentLogs(params?: LogQueryParams): Promise<NodeLog[]> {
  return get<NodeLog[]>('/api/NodeLog/recent', { params })
}

/**
 * 获取错误日志
 */
export function getErrorLogs(params?: LogQueryParams): Promise<NodeLog[]> {
  return get<NodeLog[]>('/api/NodeLog/errors', { params })
}

/**
 * 获取日志统计
 */
export function getLogStatistics(params?: LogQueryParams): Promise<LogStatistics> {
  return get<LogStatistics>('/api/NodeLog/statistics', { params })
}
